﻿/*
Copyright (c) 2009 Vratislav Cermak (vratacermak@gmail.com)
 
This file is part of TeachMe Project. See http://code.google.com/p/teach-me for more information.
 
TeachMe is an open source project. Using of TeachMe is free of charge.
It is distributed under GNU General Public License version 3 (GPLv3).
GPLv3 can be found at http://www.gnu.org/licenses/gpl.html.
 
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

using TeachMe.Application.Properties;
using System.Windows.Forms;

namespace TeachMe.Application.Forms
{
    public partial class MemoForm : PseudoModalForm
    {
        public enum Mode
        {
            Close,
            OkCancel
        }

        private Mode _mode;

        public DialogResult ResultAction { get; set;}

        public MemoForm()
        {
            InitializeComponent();

            SetMode(Mode.Close);
        }

        public void SetMode(Mode mode)
        {
            _mode = mode;

            switch (_mode)
            {
                case Mode.Close:
                    bRight.Visible = true;
                    bRight.Text = Resources.ButtonClose;
                    bRight.DialogResult = DialogResult.OK;
                    AcceptButton = bRight;
                    CancelButton = null;
                    bLeft.Visible = false;
                    break;
                case Mode.OkCancel:
                    bRight.Visible = true;
                    bRight.Text = Resources.ButtonCancel;
                    bRight.DialogResult = DialogResult.Cancel;
                    bLeft.Visible = true;
                    bLeft.Text = Resources.ButtonOk;
                    bLeft.DialogResult = DialogResult.OK;
                    AcceptButton = bLeft;
                    CancelButton = bRight;
                    break;
            }

            ResultAction = bRight.DialogResult;
        }

        public void SetCaption(string caption)
        {
            Text = caption;
        }

        public void SetText(string text)
        {
            txMemo.Text = text;
        }

        public string GetText()
        {
            return txMemo.Text;
        }

        public bool ReadOnly
        {
            set
            {
                txMemo.ReadOnly = value;
            }
        }

        private void OnRightClick(object sender, System.EventArgs e)
        {
            ResultAction = bRight.DialogResult;
        }

        private void OnLeftClick(object sender, System.EventArgs e)
        {
            ResultAction = bLeft.DialogResult;
        }
    }
}
